#ifndef MY_REGISTER_H
#define MY_REGISTER_H

#include <QWidget>
#include <QEvent>
#include <QMouseEvent>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QPainter>
#include <QRegularExpressionValidator>
#include <QRegularExpression>

class login;
namespace Ui {
class my_register;
}

class my_register : public QWidget
{
    Q_OBJECT
signals:
    void regSuccess();
public:
    explicit my_register(QWidget *parent = nullptr);
    ~my_register();
    void paintEvent(QPaintEvent *event);
    void register_successed(int res);
    static my_register* getInstance();
    static void destoryInstance();

private slots:
    void on_radioButton_clicked();

    void on_close_toolButton_clicked();

    void on_register_pushButton_clicked();


    void on_return_login_pushButton_clicked();

private:
    Ui::my_register *ui;
    static my_register* instance;
};

#endif // MY_REGISTER_H

class DragWidgetFilter_1:public QObject{
public:
    DragWidgetFilter_1(QObject* parent): QObject(parent){}

    bool eventFilter(QObject *object,QEvent *event)
    {
        auto w=dynamic_cast<QWidget*>(object);
        if(!w)
        {
            return false;
        }
        if(event->type()==QEvent::MouseButtonPress)
        {
            auto ev=dynamic_cast<QMouseEvent*>(event);
            if(!ev) return false;
            pos=ev->pos();
        }
        else if(event->type()==QEvent::MouseMove)
        {
            auto ev=dynamic_cast<QMouseEvent*>(event);
            if(!ev) return false;
            if(ev->buttons()&Qt::MouseButton::LeftButton)
            {
                w->move(ev->globalPosition().toPoint()-pos);
            }
        }
        return QObject::eventFilter(object,event);
    }
private:
    QPoint pos;
};
